package org.chengn.level_middle.context1962;

import java.util.PriorityQueue;

/**
 * @Title: Context1962
 * @Author ChengN
 * @Package org.chengn.level_middle.context1962
 * @Date 2023/12/23 0:15
 * @description: 移除石子使总数最小
 */
public class Context1962 {
    public int minStoneSum(int[] piles, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o2 - o1);
        for (int pile : piles) {
            queue.add(pile);
        }

        while (k-- > 0) {
            Integer poll = queue.poll();
            queue.add((poll + 1) >> 1);
        }

        int res = 0;
        while (!queue.isEmpty())
            res += queue.poll();

        return res;
    }
}
